package com.code.soulqlexpress.config;

import com.code.soulqlexpress.func.*;
import com.ql.util.express.ExpressRunner;
import com.ql.util.express.instruction.op.OperatorAdd;
import com.ql.util.express.instruction.op.OperatorReduce;

/**
 * @author yzh
 * @date 2020/1/17
 * @Content:表达式运行类
 */
public class QlExpressRunner {

    public static ExpressRunner expressRunner;

    private QlExpressRunner() {
    }

    static {
        expressRunner = new ExpressRunner(true, false);

        NulOperator nulOperator = new NulOperator();
        expressRunner.addFunction("nul", nulOperator);

        OperatorAdd operatorAdd = new OperatorAdd("add");
        expressRunner.addFunction("add", operatorAdd);

        OperatorReduce operatorReduce = new OperatorReduce("reduce");
        expressRunner.addFunction("reduce", operatorReduce);

        SumOperator sumOperator = new SumOperator();
        expressRunner.addFunction("sum", sumOperator);

        AvgOperator avgOperator = new AvgOperator();
        expressRunner.addFunction("avg", avgOperator);

        DecodeOperator decodeOperator = new DecodeOperator();
        expressRunner.addFunction("decode", decodeOperator);

        MyMinMaxOperator myMaxOperator = new MyMinMaxOperator("mymax");
        expressRunner.addFunction("mymax", myMaxOperator);

        MyMinMaxOperator myMinOperator = new MyMinMaxOperator("mymin");
        expressRunner.addFunction("mymin", myMinOperator);

        NextStatusOperator nextStatusOperator = new NextStatusOperator();
        expressRunner.addFunction("next_status", nextStatusOperator);

        FirstGeZeroOperator firstGeZeroOperator = new FirstGeZeroOperator();
        expressRunner.addFunction("first_ge_0", firstGeZeroOperator);

        SwitchOperator switchOperator = new SwitchOperator();
        expressRunner.addFunction("switch", switchOperator);

        InOperator inOperator = new InOperator();
        expressRunner.replaceOperator("in", inOperator);

        EqOperator eqOperator = new EqOperator();
        expressRunner.replaceOperator("==", eqOperator);

        GeOperator geOperator = new GeOperator();
        expressRunner.replaceOperator(">=", geOperator);

        GtOperator gtOperator = new GtOperator();
        expressRunner.replaceOperator(">", gtOperator);

        LeOperator leOperator = new LeOperator();
        expressRunner.replaceOperator("<=", leOperator);

        LtOperator ltOperator = new LtOperator();
        expressRunner.replaceOperator("<", ltOperator);

        DivOperator divOperator = new DivOperator();
        expressRunner.addFunction("div", divOperator);

        MinusOperator minusOperator = new MinusOperator();
        expressRunner.addFunction("minus", minusOperator);
    }
}
